﻿<%@ Page Title="Mobilhjulskift.dk - Webshop" Language="C#" MasterPageFile="~/Webshop/Webshop.master" AutoEventWireup="true" CodeBehind="Daek.aspx.cs" Inherits="TireService.Website.Webshop.Daek" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">

    <script type="text/javascript">
    // <![CDATA[
        function OnWidthChanged(ddlWidth) {
            ddlHeight.PerformCallback(ddlWidth.GetValue().toString());
        }

        function OnHeightChanged(ddlHeight) {

            var input = ddlWidth.GetValue().toString() + '|' + ddlHeight.GetValue().toString();

            ddlSize.PerformCallback(input);
        }

        function CheckWidthText(s, e) 
        {
            if (txtWidth.GetText().length == 3) {
                txtHeight.Focus();
            }
        }

        function CheckHeightText(s, e) {
            if (txtHeight.GetText().length == 2) {
                txtSize.Focus();
            }
        }

        function SearchTires(s, e) {
            // TODO: 
        }

        function ShowAddProduct(itemnumber) {
            lblProductNumber.SetText(itemnumber);

            pcAddToShoppingCart.Show();
        }

        function AddToCart(itemnumber) {

            // Validate form
            txtQuantity.Validate();

            var isFormValid = ASPxClientEdit.ValidateGroup("AddToCart");
            if (isFormValid) {

                var input = itemnumber + '|' + txtQuantity.GetText();

                // Do server callback and add product to basket
                callBackAddProduct.PerformCallback(input);
            }
        }

        function AddToCartAndCheckOut(itemnumber) {
            // Validate form
            txtQuantity.Validate();

            var isFormValid = ASPxClientEdit.ValidateGroup("AddToCart");
            if (isFormValid) {

                var input = itemnumber + '|' + txtQuantity.GetText();

                // Do server callback and add product to basket
                callBackAddProductAndCheckOut.PerformCallback(input);
            }
        }

        // Function that runs when server postback done
        function OnCallbackAddProductComplete(s, e) {
            pcAddToShoppingCart.Hide();

//            LoadingPanel.Hide();

//            alert('Vare blev tilføjet indkøbskurven');
        }

        function OnCallbackAddProductAndCheckOutComplete(s, e) {
            pcAddToShoppingCart.Hide();

            // TODO: Redirect to shopping cart
            window.location = "Kurv.aspx";
        }

        // Error happend
        function CallBackError(s, e) {
            alert('Fejl opstod, venligst prøv igen');
        }

    // ]]> 
    </script>

    <dx:ASPxLoadingPanel ID="LoadingPanel" Text="Vent venligst..." ClientInstanceName="LoadingPanel" runat="server" Modal="True">
    </dx:ASPxLoadingPanel>

    <dx:ASPxCallback ID="callBackAddProduct" ClientInstanceName="callBackAddProduct"
        runat="server" OnCallback="callBackAddProduct_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackAddProductComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackAddProductAndCheckOut" ClientInstanceName="callBackAddProductAndCheckOut"
        runat="server" OnCallback="callBackAddProductAndCheckOut_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackAddProductAndCheckOutComplete" />
    </dx:ASPxCallback>

    <!-- Modal popup that fires when user has selected to add product to shoppingcart -->
    <dx:ASPxPopupControl ID="pcAddToShoppingCart" runat="server" CloseAction="None"
        Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        ClientInstanceName="pcAddToShoppingCart" HeaderText="Tilføj til indkøbskurv" EnableAnimation="False"
        EnableViewState="False" ClientIDMode="AutoID" EnableHotTrack="False">
        <LoadingPanelStyle ImageSpacing="5px">
        </LoadingPanelStyle>
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxPanel ID="Panel1" runat="server" DefaultButton="btOK">
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent1" runat="server">
                            
                            <table width="350px">
                                <tr>
                                    <td colspan="2">
                                        <h1>Tilføj til indkøbskurv</h1>
                                        <dx:ASPxSpinEdit runat="server" Number="4" MinValue="1" MaxValue="99" ID="txtQuantity"
                                            ClientInstanceName="txtQuantity" Width="50px" Height="21px">
                                            <ValidationSettings ValidationGroup="AddToCart" RequiredField-ErrorText="Antal skal angives"
                                                ErrorDisplayMode="ImageWithTooltip" RequiredField-IsRequired="true">
                                            </ValidationSettings>
                                        </dx:ASPxSpinEdit>
                                        <dx:ASPxLabel ID="lblProductNumber" ClientInstanceName="lblProductNumber" ClientVisible="false" runat="server" Text="">
                                        </dx:ASPxLabel>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <dx:ASPxButton ID="btnAdd" runat="server" Text="Tilføj og fortsæt shopping" AutoPostBack="false" UseSubmitBehavior="False" Width="175px" Height="40px">
                                            <ClientSideEvents Click="function() { AddToCart(lblProductNumber.GetText()); }" />
                                        </dx:ASPxButton>
                                    </td>
                                    <td valign="top">
                                        <dx:ASPxButton ID="btnAddandCheckOut" runat="server" Text="Tilføj og gå til indkøbskurv" AutoPostBack="false" UseSubmitBehavior="False" Width="175px" Height="40px">
                                            <ClientSideEvents Click="function() { AddToCartAndCheckOut(lblProductNumber.GetText()); }" />
                                        </dx:ASPxButton>

                                    </td>
                                </tr>
                                <tr>
                                    <td align="left">
                                        <%--<dx:ASPxButton ID="btnContinueSignup" runat="server" ClientIDMode="AutoID" 
                                            Text="Tilbage til bestilling" >
                                            <ClientSideEvents Click="function(s, e) { pcCancelSignup.Hide(); }" />
                                        </dx:ASPxButton>--%>
                                    </td>
                                    <td align="right">
                                        <%--<asp:LinkButton ID="lbtnCancelSignup" runat="server" 
                                            OnClick="lbtnCancelSignup_Click">Til startsiden</asp:LinkButton>        --%>
                                    </td>
                                </tr>
                            </table>
                            
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>


    <h1>Bildæk</h1>
    <table>
        <tr style="width:480px">
            <td style="width:120px"><b>Dækstørrelse</b></td>
            <td style="width:120px"><b>Type</b></td>
            <td style="width:120px"></td>
        </tr>
        <tr>
            <td valign="top">
                <dx:ASPxTextBox ID="txtWidth" ClientInstanceName="txtWidth" NullText="Bredde - ex. 195" runat="server" Width="120px">
                    <ClientSideEvents KeyUp="function(s, e) { CheckWidthText(s, e); }" />
                </dx:ASPxTextBox>
                <%--<dx:ASPxComboBox ID="ddlWidth" ClientInstanceName="ddlWidth" runat="server" Width="120px" IncrementalFilteringMode="StartsWith">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnWidthChanged(s); }" />
                </dx:ASPxComboBox>--%>
            </td>
            <td rowspan="3" valign="top">
                <dx:ASPxRadioButtonList ID="rbtnTireType" runat="server" RepeatDirection="Vertical" Height="75px" Width="120px">
                    <RadioButtonStyle Font-Size="Large"></RadioButtonStyle>
                    <Items>
                        <dx:ListEditItem Value="2" Text="Sommerdæk" />
                        <dx:ListEditItem Value="3" Text="Vinterdæk" />
                    </Items>
                </dx:ASPxRadioButtonList>
            </td>
            <td rowspan="3" valign="top">
                <dx:ASPxButton ID="btnSearchTire" ClientInstanceName="btnSearchTire" 
                    runat="server" Font-Size="Large" Text="Søg dæk" Width="120px" Height="75px" 
                    onclick="btnSearchTire_Click">
                </dx:ASPxButton>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <%--<dx:ASPxComboBox ID="ddlHeight" ClientInstanceName="ddlHeight" runat="server" Width="120px" IncrementalFilteringMode="StartsWith" OnCallback="ddlHeight_Callback">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnHeightChanged(s); }" EndCallback="function(s, e) { OnHeightChanged(s); }" />
                </dx:ASPxComboBox>--%>
                <dx:ASPxTextBox ID="txtHeight" ClientInstanceName="txtHeight" NullText="Profil - ex. 50" runat="server" Width="120px">
                    <ClientSideEvents KeyUp="function(s, e) { CheckHeightText(s, e); }" />
                </dx:ASPxTextBox>
            </td>
        </tr>
        <tr>
            <td valign="top">

                <%--<dx:ASPxComboBox ID="ddlSize" ClientInstanceName="ddlSize" runat="server" Width="120px" IncrementalFilteringMode="StartsWith" OnCallback="ddlSize_Callback">
                </dx:ASPxComboBox>--%>

                <dx:ASPxTextBox ID="txtSize" ClientInstanceName="txtSize" NullText="Diameter - ex. 15" runat="server" Width="120px">
                    <ClientSideEvents KeyDown="function(s, e) {if(ASPxClientUtils.GetKeyCode(e.htmlEvent) ===  ASPxKey.Enter) SearchTires();}" />
                </dx:ASPxTextBox>
            </td>
        </tr>
    </table>
    <hr />
    <dx:ASPxGridView ID="gvTires" ClientInstanceName="gvTires" runat="server" Width="100%" KeyFieldName="TirePriceListId" AutoGenerateColumns="false">
    
        <Templates>
            <PreviewRow>
                <table width="100%">
                    <tr>
                        <td valign="top" align="center" style="width:100px">
                            <dx:ASPxImage ID="ASPxImage5" ImageUrl='<%# Eval("ImagePath")%>' runat="server" Height="100px">
                            </dx:ASPxImage>
                        </td>
                        <td valign="top" style="width:320px">
                            <b><%# Eval("FullDescription") %></b><br />
                            <%# Eval("Width") %>/<%# Eval("Height") %>R<%# Eval("Size") %> - Loadindex <%# Eval("TireLoadDescription") %> - <%# Eval("TireSpeedDescription") %><br />
                            Dæktype: <%# DeterminTireType(Eval("TireTypeId"))%>
                        </td>
                        <td>
                            <table>
                                <tr>
                                    <td>
                                        <dx:ASPxImage ID="ASPxImage2" ToolTip="Brændstofforbrug" ImageUrl="~/Images/Webshop/effektivt.png" runat="server">
                                        </dx:ASPxImage>
                                    </td>
                                    <td>
                                        <dx:ASPxImage ID="imgEfficency" ImageUrl='<%# GetImagePath(Eval("FuelEconomy").ToString())%>' Visible='<%# (Eval("FuelEconomy").ToString() != "0")%>' runat="server">
                                        </dx:ASPxImage>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <dx:ASPxImage ID="ASPxImage4" ToolTip="Vejgreb" ImageUrl="~/Images/Webshop/vejgreb.png" runat="server">
                                        </dx:ASPxImage>
                                    </td>
                                    <td>
                                        <dx:ASPxImage ID="imgRoad" ImageUrl='<%# GetImagePath(Eval("RoadGrip").ToString())%>' Visible='<%# (Eval("RoadGrip").ToString() != "0")%>' runat="server">
                                        </dx:ASPxImage>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <dx:ASPxImage ID="ASPxImage3" ToolTip="Støjniveau" ImageUrl="~/Images/Webshop/lyd.png" runat="server">
                                        </dx:ASPxImage>
                                    </td>
                                    <td>
                                        <%# Eval("NoiseValue").ToString()%>db
                                    </td>
                                </tr>
                                
                            </table>
                        </td>
                        <td style="width:200px">
                            Pr. stk. inkl. moms<br />
                            kun DKK
                            <h3>Pris - <%# CalculateCostPrice(Eval("CostPrice").ToString(), Eval("Size").ToString())%></h3>
                            <br />
                            <table width="150px">
                                <tr>
                                    <td>
                                        
                                    </td>
                                    <td>
                                        <dx:ASPxButton ID="btnAddToCart" ClientInstanceName="btnAddToCart" runat="server" Width="100px" OnInit="btnAddToCart_Init"
                                            Text="Tilføj til kurv" AutoPostBack="False" UseSubmitBehavior="False">
                                        </dx:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </PreviewRow>
        </Templates>
        <Settings ShowPreview="true" ShowGroupPanel="false" />
        <SettingsPager PageSize="30" />

    </dx:ASPxGridView>

</asp:Content>
